<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../../header.jsp"%>

<script type="text/javascript">
var detailValidator;
var assignValidator;

// function selectTemplate() {
// 	$.openDialog("#dialog",
// 			{height:550,
// 			width:800,
// 			minHeight:450,
// 			minWidth:600,
// 			loadPage:ctx + "/biz/template/query.do",
// 			title:"选择模板"},
// 			function(data) {
// 				$("#taskTemplate").data("id",data.id);
// 				$("#taskTemplate").val(data.name);
// 			});
// }

// function selectExecutePerson() {
// 	$.openDialog("#dialog",
// 			{height:350,
// 			width:300,
// 			minHeight:350,
// 			minWidth:300,
// 			loadPage:ctx + "/biz/system/user/tree.jsp",
// 			title:"选择勘察人员"},
// 			function(data) {
// 				alert(data);
// 				$("#taskExecPerson").data("id",data.data("id"));
// 				$("#taskExecPerson").val(data.data("name"));
// 			});
// }

function selectProject() {
	$.openDialog("#dialog",
			{height:550,
			width:800,
			minHeight:450,
			minWidth:600,
			loadPage:ctx + "/biz/project/query.do",
			title:"选择项目"},
			function(data) {
				$("#taskProject").data("id",data.id);
				$("#taskProject").val(data.name);
			});
}

function selectPlanPoint() {
	$.openPointSelect("#dialog",
			{
				loadPage:ctx + "/biz/task/map_select.jsp",
				title:"点击地图选择坐标"
			},
			function(data) {
				$("#taskPlanLongitude").val(data.longitude);
				$("#taskPlanLatitude").val(data.latitude);
				$("#planLocationProvice").val(data.locationProvice);
				$("#planLocationCity").val(data.locationCity);
				$("#planLocationCounty").val(data.locationCounty);
				$("#planLocationStreet").val(data.locationStreet);
				$("#planLocationNumber").val(data.locationNumber);
				$("#planLocationAddress").val(data.locationAddress);
			}
	);
}

function doDelete() {
	if (!confirm('是否删除？\n请确认是否继续操作 ！')) {
		return;
	}
	
	block("#detailForm");
	var id = $("#taskId").val();
	$.ajax({
		type: "POST",
		url: "delete.json",
		data: {"id": id},
		dataType: "json",
		success: function(data){
			unblock("#detailForm");
			if(!data.succeed){
				$.alert("删除失败，原因为：\n" + data.message);
				return;
			}
			$.info("删除成功！");
			goBack1();
		},
		error: function(message){
			unblock("#detailForm");
			$.alert("删除失败：" + message);
		}
	});
}

function getTaskData(){
	var data = {
			id: $("#taskId").val(),
			name: $("#taskName").val(),
			//code: $("#taskCode").val(),
			//status: $("#taskStatus").data("code"),
			//planLongitude: $("#taskPlanLongitude").val(),
			//planLatitude: $("#taskPlanLatitude").val(),
			//planLocationProvice: $("#planLocationProvice").val(),
			//planLocationCity: $("#planLocationCity").val(),
			//planLocationCounty: $("#planLocationCounty").val(),
			//planLocationStreet: $("#planLocationStreet").val(),
			//planLocationNumber: $("#planLocationNumber").val(),
			//planLocationAddress: $("#planLocationAddress").val(),
			//planStartDate: $("#taskPlanStartDate").val(), 
			planEndDate: $("#taskPlanEndDate").val(),
			//stationCode: $("#taskStationCode").val(),
			//stationName: $("#taskStationName").val(),
			//projectId: $("#taskProject").data("id"),
			//managerName: $("#taskManagerName").val(),
			//districtCode: $("#taskDistrict").data("code"),
			//districtName: $("#taskDistrict").val(),
			//execOrganId: $("#taskExecOrgan").data("id"),
			execPersonId: $("#taskExecPerson").data("id"),
			projectId: $("#taskProject").data("id"),
			content: $("#taskContent").val()
		};
	return data;
}

function doSave() {
	if (!detailValidator.form()) {
		return;
	}
	
	block("#detailForm");
	$.ajax({
		type: "POST",
		url: "save.json",
		data: getTaskData(),
		dataType: "json",
		success: saveSucceedCallback,
		error:function(message){
			unblock("#detailForm");
			$.alert("出错了，错误信息为：\n"+message);
		}
	});
}

function loadItem(){
	var id = request("id");
	if(id == undefined || id == ""){
		return;
	}
	
	block("#detailForm");
	$.ajax({
		type: "GET",
		cache: false,
		url: "detail.json?id=" + id,
		dataType: "json",
		success: loadSucceedCallback,
		error:function(message){
			unblock("#detailForm");
			$.alert(message);
		}  
	});	
}

function loadSucceedCallback(data){
	unblock("#detailForm");
	if (!data.succeed) {
		$.notice(data.message);
		return;
	}
	var status = data.data.status;
	if(status == "in_process" || status == "completed" || status == ""){
		location.href = "detail.do?id=" + data.data.id;
	}
	if(status == "assigned" || status == "draft"){
		$("#deleteBtn").show();
	}
	fillItem(data.data);
}

function fillItem(item){
	$("#taskTitle").text(" - " + item.name);
	$("#taskId").val(item.id);
	$("#taskName").val(item.name);
	//$("#taskCode").val(item.code);
	$("#taskStatus").val(getTaskStatus(item.status));
	$("#taskStatus").data("code", item.status);
	//$("#taskAssignedDate").val(item.assignedDate);
	//$("#taskProject").val(item.projectName);
	//$("#taskProject").data("id", item.projectId);
	//$("#taskManagerName").val(item.managerName);
	//$("#taskPlanStartDate").val((item.planStartDate!=null)?item.planStartDate.slice(0,10):item.planStartDate);
	$("#taskPlanEndDate").val((item.planEndDate!=null)?item.planEndDate.slice(0,10):item.planEndDate);
	//$("#taskStartDate").val(item.startDate);
	//$("#taskEndDate").val(item.endDate);
	//$("#taskPlanLongitude").val(item.planLongitude);
	//$("#taskPlanLatitude").val(item.planLatitude);
	//$("#planLocationProvice").val(data.planLocationProvice);
	//$("#planLocationCity").val(data.planLocationCity);
	//$("#planLocationCounty").val(data.planLocationCounty);
	//$("#planLocationStreet").val(data.planLocationStreet);
	//$("#planLocationNumber").val(data.planLocationNumber);
	//$("#planLocationAddress").val(data.planLocationAddress);
	//$("#taskDistrict").val(item.districtName);
	//$("#taskDistrict").data("code", item.districtCode);
	//$("#taskStationCode").val(item.stationCode);
	//$("#taskStationName").val(item.stationName);
	$("#taskExecOrgan").val(item.execOrganName);
	$("#taskExecOrgan").data("id", item.execOrganId);
	$("#taskExecPerson").val(item.execPersonName);
	$("#taskExecPerson").data("id", item.execPersonId);
	$("#taskProject").val(item.projectName);
	$("#taskProject").data("id", item.projectId);
	$("#taskContent").val(item.content);
	$("#taskCreator").val(item.creatorName);
	$("#taskCreator").data("id", item.creatorId);
	$("#taskCreateDateTime").val(item.createDateTime);
	
	$("#taskCreatorCg").show();
	$("#taskCreateDateTimeCg").show();
	$("#taskStatusCg").show();

	/**
	if(item.status == "draft"){
		$("#assignBtn").show();
		$("#saveBtn").show();
		$("#deleteBtn").show();
		$("#taskAssignedDateCg").hide();
	} else {
		$("#assignBtn").hide();
		$("#saveBtn").hide();
		$("#deleteBtn").hide();
		$("#taskAssignedDateCg").show();
	}
	if(item.status == "completed"){
		$("#taskStartDateCg").show();
		$("#taskEndDateCg").show();
	}
	*/
	
}

$(document).ready(function() {
	$("#excel_button").on('click', function() {  
        var excel_file = $("#excel_file").val();  
        if (excel_file == "" || excel_file.length == 0) {  
            alert("请选择文件路径！");  
            return false;  
        } else {  
            return true;  
        }  
    });
	
	var msg = $("#msg").val();
	if(msg =! ""){
		$("#resultCg").show();
	}
});


</script>
<input type="hidden" id="msg" value="${msg}">
	<div class="control-group" style="display: none;" id="resultCg">
			<label for="taskName"  class="control-label">导入结果：</label>
			<div class="controls">
				${msg}
			</div>
	</div>
<!-- <div class="control-group"> -->
<!-- 		<label for="taskExecPerson"  class="control-label">勘察人员：</label> -->
<!-- 		<div class="controls"> -->
<!-- 		<input type="text" id="taskExecPerson" name="taskExecPerson" readonly="readonly" /> -->
<!-- 		<a href="javascript:;" class="btn" onclick="selectExecutePerson()">选择</a> <span class="cms_color_required">*</span> -->
<!-- 		</div> -->
<!-- 	</div> -->
<form name="excelImportForm" action="<%=ctx%>/biz/task/importBrandSort.do" 
	method="post" onsubmit="return checkImportPath();" enctype="multipart/form-data" id="excelImportForm">  
    <input  type="hidden" name="ids" id="ids">  
    <div class="control-group">  
        <div class="control-group">  
            <label class="control-label">
            <input class="btn btn-default" id="excel_file" type="file" name="filename"  accept="xls"/></label>  
            <div class="controls"> 
             	<input class="btn" id="excel_button" type="submit" value="导入Excel"/>  
            </div> 
            <div class="controls">  
		         <button type="button" class="btn" data-dismiss="modal" onClick="uncheckBoxes();">取消</button>  
		 	</div>  
        </div>          
    </div>  
     
    
</form>
